﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Transport
{
    public class MienControl
    {
        transportEntities db;

        public MienControl()
        {
            db = new transportEntities();
        }

        public List<mien> listAll()
        {
            try
            {
                return db.miens.ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public string getID(string name)
        {
            try
            {
                List<mien> ls = db.miens.Where(t => t.ten_mien == name).ToList();

                if (ls.Count > 0)
                    return ls[0].ma_mien;
                else
                    return "";
            }
            catch (Exception)
            {
                return "";
            }
        }

        public string getName(string ID)
        {
            try
            {
                mien m = db.miens.SingleOrDefault(t => t.ma_mien == ID);

                if (m != null)
                    return m.ten_mien;
                else
                    return "";
            }
            catch (Exception)
            {
                return "";
            }
        }
    }
}